package vn.edu.uit.hotelbooking.JsonParse;

import java.util.ArrayList;

import org.json.JSONArray;

import vn.edu.uit.hotelbooking.model.Hotel;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class HotelParser {
    private static final String LOG_TAG= "HotelParser";
    private static Gson gson = new Gson();
    
    /**
     * The method to get a district arraylist from JSON object
     * @param jObject the JSON object
     * @return If success, return a district arraylist. If fail, return null.
     */
    public static ArrayList<Hotel> getHotelFromJson (JSONArray jObject) {
        ArrayList<Hotel> arraylist = new ArrayList<Hotel>();
        try {
            arraylist = gson.fromJson(jObject.toString(), new TypeToken<ArrayList<Hotel>>(){}.getType());
             return arraylist;
        } catch (Exception e) {
            // TODO: handle exception
            Log.e(LOG_TAG, e.getMessage());
        }
        return null;
    }
}
